{-
 
  Copyright 2022-23, Juspay India Pvt Ltd
 
  This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License
 
  as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program
 
  is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of
 
  the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
-}

module Components.ChatView.Controller where

import PrestoDOM.Types.DomAttributes (Padding(..), Margin(..))
import Data.Maybe (Maybe(..))

import Prelude (class Show)

instance showAction :: Show Action where
  show (SendMessage) = "SendMessage"
  show (SendSuggestion _) = "SendSuggestion"
  show (BackPressed) = "BackPressed"
  show (TextChanged _) = "TextChanged"
  show (EnableSuggestions) = "EnableSuggestions"
  show (Call) = "Call"
  show (Navigate) = "Navigate"
  show (NoAction) = "NoAction"
  show (OnImageClick _) = "OnImageClick"
  show (MessageAnimationEnd) = "MessageAnimationEnd"
  show (OnClickMessageAction _ ) = "OnClickMessageAction"

data Action = SendMessage
            | SendSuggestion String
            | BackPressed
            | TextChanged String
            | EnableSuggestions
            | Call
            | Navigate
            | NoAction
            | OnImageClick String
            | MessageAnimationEnd
            | OnClickMessageAction ChatComponentConfig

type Config = 
  { userConfig :: UserConfig
  , messages :: Array ChatComponentConfig
  , messagesSize :: String
  , sendMessageActive :: Boolean
  , vehicleNo :: String
  , chatSuggestionsList :: Array String
  , suggestionDelay :: Int
  , spanParent :: Boolean
  , showTextEdit :: Boolean
  , hint :: String
  , suggestionHeader :: String
  , emptyChatHeader :: String
  , showHeader :: Boolean
  , showStroke :: Boolean
  , languageKey :: String
  , mapsText :: String
  , enableSuggestionClick :: Boolean
  , transparentGrey :: String
  , canSendSuggestion :: Boolean
  , enableCall :: Boolean
  , showAutoGeneratedText :: Boolean
  , rideConfirmedAt :: String
  , autoGeneratedText :: String
  , enableSuggestions :: Boolean
  , chatBodyPadding :: Padding
  , chatMargin :: Margin 
  , showNavigate :: Boolean
  , useSuggestionsView :: Boolean
  , footerBanner :: FooterBannerConfig
  }

type FooterBannerConfig = {
  text :: String,
  enable :: Boolean
}

type UserConfig =
  { userName :: String
  , appType :: String
  }


type ChatComponentConfig = {
    message :: String 
  , messageTitle :: Maybe String
  , messageAction :: Maybe String
  , messageLabel :: Maybe String
  , sentBy :: String 
  , timeStamp :: String
  , type :: String
  , delay :: Int
}

config :: Config
config = 
  {
    userConfig : 
        {
          userName : ""
        , appType : ""
        }
    , messages : []
    , messagesSize : ""
    , sendMessageActive : false
    , vehicleNo : ""
    , chatSuggestionsList : []
    , hint : ""
    , suggestionHeader : ""
    , suggestionDelay : 0
    , spanParent : false
    , emptyChatHeader : ""
    , languageKey : ""
    , mapsText : ""
    , enableSuggestionClick : true
    , showHeader : true
    , showStroke : true
    , transparentGrey : ""
    , showTextEdit : true
    , canSendSuggestion : true
    , enableCall : true 
    , showAutoGeneratedText : false
    , rideConfirmedAt : ""
    , autoGeneratedText : ""
    , enableSuggestions : true
    , chatBodyPadding : Padding 0 0 0 0
    , chatMargin : Margin 0 0 0 0
    , showNavigate : true
    , useSuggestionsView : true
    , footerBanner : {
        text : "",
        enable : true
    }
  }

makeChatComponent' :: String -> Maybe String -> Maybe String -> Maybe String -> String -> String -> String -> Int -> ChatComponentConfig 
makeChatComponent' message messageTitle messageAction messageLabel sender timeStamp type' delay =  {
  "message" : message
, "messageTitle" : messageTitle
, "messageAction" : messageAction
, "messageLabel" : messageLabel
, "sentBy" : sender
, "timeStamp" : timeStamp
, "type" : type'
, delay : delay
}

makeChatComponent :: String -> Maybe String -> Maybe String -> Maybe String -> String -> String -> ChatComponentConfig
makeChatComponent message messageTitle messageAction messageLabel sender timeStamp =  {
  "message" : message
, "messageTitle" : messageTitle
, "messageAction" : messageAction
, "messageLabel" : messageLabel
, "sentBy" : sender
, "timeStamp" : timeStamp
, "type" : "Text"
, delay : 0
}
